/*
 *   The contents of this file are subject to the Mozilla Public License
 *   Version 1.1 (the "License"); you may not use this file except in
 *   compliance with the License. You may obtain a copy of the License at
 *   http://www.mozilla.org/MPL/
 *
 *   Software distributed under the License is distributed on an "AS IS"
 *   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 *   License for the specific language governing rights and limitations
 *   under the License.
 *
 *   The Original Code is OkkamNGClient, in the package org.okkam.client.*.
 *
 *   The Initial Developer of the Original Code is 
 *		Heiko Stoermer (http://disi.unitn.it/~stoermer).
 *
 *   Portions created by the Initial Developer are Copyright (C) 2007
 *   the Initial Developer. All Rights Reserved.
 *
 *   Contributor(s): Daniel Giacomuzzi (etadaniel@gmail.com).
 *
*/
package org.okkam.client.wsclient;

import java.io.StringReader;
import java.rmi.RemoteException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.okkam.core.api.data.entityprofile.EntityProfile;
import org.okkam.webservice.ProfileRetrieverProxy;

/**
 * Web service client that interfaces with the ProfileRetriever service. Fetches an entity profile by OKKAM ID.
 * 
 * <h2>Example</h2>
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = -->
<!-- =   Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard  markus@jave.de   = -->
<!-- =     Further information: http://www.java2html.de     = -->
<div align="left" class="java">
<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
   <tr>
  <!-- start source code -->
   <td nowrap="nowrap" valign="top" align="left">
    <code>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">ProfileRetrieverClient&nbsp;prc&nbsp;=&nbsp;</font><font color="#7f0055"><b>new&nbsp;</b></font><font color="#000000">ProfileRetrieverClient</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#7f0055"><b>try&nbsp;</b></font><font color="#000000">{</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">EntityProfile&nbsp;pro&nbsp;=&nbsp;prc.getProfile</font><font color="#000000">(</font><font color="#2a00ff">&#34;http://www.okkam.org/entity/43da58d8-2fcf-4a7d-aba0-417a22a8c562&#34;</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#000000">pro.getOkkamURI</font><font color="#000000">())</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><b>catch&nbsp;</b></font><font color="#000000">(</font><font color="#000000">RemoteException&nbsp;e</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">e.printStackTrace</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}&nbsp;</font><font color="#7f0055"><b>catch&nbsp;</b></font><font color="#000000">(</font><font color="#000000">JAXBException&nbsp;e</font><font color="#000000">)&nbsp;{</font><br />
<font color="#ffffff"></font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">e.printStackTrace</font><font color="#000000">()</font><font color="#000000">;</font><br />
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">}</font></code>
    
   </td>
  <!-- end source code -->
   </tr>
</table>
</div>

 * 
 * @author stoermer
 *
 */

public class ProfileRetrieverClient 
{

	ProfileRetrieverProxy proxy;
	
	public ProfileRetrieverClient()
	{
		proxy = new ProfileRetrieverProxy();
	}
	
	/**
	 * Retrieves a EntityProfile object from an okkam uri.
	 * @param okkamuri 
	 * @return Instance of {@link org.okkam.core.api.data.entityprofile.EntityProfile}
	 * @throws RemoteException
	 * @throws JAXBException
	 */
	public EntityProfile getProfile(String okkamuri) throws RemoteException, JAXBException 
	{
		String profilexml = proxy.getProfileForURI(okkamuri);
		JAXBContext jc = JAXBContext.newInstance("org.okkam.core.api.data.entityprofile",getClass().getClassLoader());
		Unmarshaller unmarshaller = jc.createUnmarshaller();
		EntityProfile profile = (EntityProfile) unmarshaller.unmarshal(new StringReader(profilexml));
		return profile;
	}
	
}
